import config
from dingtalk import api 


def get_access_token():
    req = api.OapiGettokenRequest("https://oapi.dingtalk.com/gettoken")
    req.appkey = config.DING_APPKEY
    req.appsecret = config.DING_APPSECRET

    try:
        return req.getResponse()
    except Exception as e:
        return str(e)


def upload_attendance_record(access_token, user_id, device_name, device_id, user_check_time):
    req = api.OapiAttendanceRecordUploadRequest("https://oapi.dingtalk.com/topapi/attendance/record/upload")
    req.userid = user_id
    req.device_name = device_name
    req.device_id = device_id
    req.user_check_time = user_check_time

    try:
        return req.getResponse(access_token)
    except Exception as e:
        return str(e)
